﻿using Communication.Model.acceleration;
using Communication.Model.displacement;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;


namespace UI.TestModule
{
    public enum ChannelType
    {
        Acceleration,
        Displacement,
        RPM,
        None
    }
    public class GlobalVariable
    {
        public static int ChannelNum = 32;
        public static DisplacementData DptCurrent;
        public static AccData AccCurrent;
        //public static List<TestChannel> TestCHList;
    }
    public class TestChannel : IComparable
    {
        public TestChannel(int id, string name, ChannelType type)
        {
            Id = id;
            ChannelName = name;
            Type = type;
            VolTested = new List<float>();
        }
        public int Id { get; set; }
        public string ChannelName { get; set; }
        public ChannelType Type { get; set; }
        public List<float> VolTested;
        public int CompareTo(object obj)
        {
            if (obj is TestChannel)
            {
                TestChannel temp = obj as TestChannel;
                return this.Id.CompareTo(temp.Id);
            }
            throw new NotImplementedException("对象不匹配！");
        }
    }
    public class TestHelper
    {
        public TestHelper()
        {
            TestCHList = new List<TestChannel>();
            IsChecked = new bool[GlobalVariable.ChannelNum];
            for (int i = 0; i < GlobalVariable.ChannelNum; i++)
            {
                IsChecked[i] = false;
            }
        }

        private bool[] IsChecked;
        public List<TestChannel> TestCHList;
        public void CheckChannel(int id)
        {
            IsChecked[id] = true;
        }

        public void ChooseChannel(int id, string name, ChannelType type)
        {
            TestChannel cc = new TestChannel(id, name, type);
            TestCHList.Add(cc);
            TestCHList.Sort();
        }
        public bool IsChoosed(int id)
        {
            for (int i = 0; i < TestCHList.Count; i++)
            {
                if (TestCHList[i].Id == id)
                    return true;
            }
            return false;
        }
        public void Clear()
        {
            for (int i = 0; i < GlobalVariable.ChannelNum; i++)
            {
                IsChecked[i] = false;
            }
            TestCHList.Clear();
            //(obj as Label).BackColor = Color.White;
        }
    }
}
